﻿using TodoPro.System.Event;

namespace TodoPro.System.Command
{
    public class AddTodoCommand : ITodoCommand
    {
        private readonly string mContent = null;
        private readonly ITodoModel mTodoModel = null;
        
        public AddTodoCommand(string content)
        {
            mContent = content;

            mTodoModel = TodoProConfig.GetModel<ITodoModel>();
        }

        public void Execute()
        {
            var todo = new Todo() {Content = mContent};
            
            mTodoModel.Add(todo);
            
            TodoProConfig.SendEvent(new OnTodoAddEvent()
            {
                TodoId = todo.Id
            });
        }
    }
}